package com.bootdo.appsystem.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.appsystem.domain.ImageinfoDO;
import com.bootdo.appsystem.domain.OrderproductDO;
import com.bootdo.appsystem.service.ImageinfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.appsystem.domain.ProducesinfoDO;
import com.bootdo.appsystem.service.ProducesinfoService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 *
 * 商品
 * @author xiaoxiao
 * @email 806191255@qq.com
 * @date 2018-05-12 14:42:14
 */
 
@Controller
@RequestMapping("/appsystem/producesinfo")
public class ProducesinfoController {
	@Autowired
	private ProducesinfoService producesinfoService;
	@Autowired
    private ImageinfoService imageinfoService;
	
	@GetMapping()
	@RequiresPermissions("appsystem:producesinfo:producesinfo")
	String Producesinfo(){
	    return "appsystem/producesinfo/producesinfo";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("appsystem:producesinfo:producesinfo")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ProducesinfoDO> producesinfoList = producesinfoService.list(query);
		int total = producesinfoService.count(query);
		PageUtils pageUtils = new PageUtils(producesinfoList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("appsystem:producesinfo:add")
	String add(){
	    return "appsystem/producesinfo/add";
	}

	@GetMapping("/edit/{pid}")
	@RequiresPermissions("appsystem:producesinfo:edit")
	String edit(@PathVariable("pid") Integer pid,Model model){
		ProducesinfoDO producesinfo = producesinfoService.get(pid);
		model.addAttribute("producesinfo", producesinfo);
	    return "appsystem/producesinfo/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("appsystem:producesinfo:add")
	public R save( ProducesinfoDO producesinfo){
		if(producesinfoService.save(producesinfo)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("appsystem:producesinfo:edit")
	public R update( ProducesinfoDO producesinfo){
		producesinfoService.update(producesinfo);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("appsystem:producesinfo:remove")
	public R remove( Integer pid){
		if(producesinfoService.remove(pid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("appsystem:producesinfo:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] pids){
		producesinfoService.batchRemove(pids);
		return R.ok();
	}


	@GetMapping("/editImage/{pid}")
	@RequiresPermissions("appsystem:producesinfo:editImage")
	String editImage(@PathVariable("pid") Integer pid,Model model){
        ProducesinfoDO producesinfoDO = producesinfoService.get(pid);
        model.addAttribute("producesinfo", producesinfoDO);
		return "appsystem/producesinfo/editImage";
	}

    @ResponseBody
    @GetMapping("/listImages")
    @RequiresPermissions("appsystem:producesinfo:editImage")
    public PageUtils listImages(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        Integer[] integers = {12009,12010};
        query.put("typein", integers);
        List<ImageinfoDO> imageinfoDOList = imageinfoService.list(query);
        int total = imageinfoService.count(query);
        PageUtils pageUtils = new PageUtils(imageinfoDOList, total);
        return pageUtils;
    }
	
}
